package service.impl;


import dao.PageDao;
import dao.impl.PageDaoImpl;
import pojo.Note;
import pojo.Page;
import pojo.User;
import service.PageService;
import util.PageUtils;

import java.sql.SQLException;
import java.util.ArrayList;

public class PageServiceImpl implements PageService {
    PageDao pageDao = new PageDaoImpl();

    @Override
    public Page<Note> findPageNote(Integer currentPage1, Integer rows1, int start) throws SQLException, ClassNotFoundException {
        Page<Note> pageNote = new Page<>();
        int total = pageDao.totalNotes();
//        pageNote=PageUtils.findPageNote(currentPage1,rows1);
        System.out.println(start);
        System.out.println(rows1);
        ArrayList<Note> list = new ArrayList<>();
        list = pageDao.list(start, rows1);
        pageNote = PageUtils.page(list, currentPage1, rows1, total);
        return pageNote;
    }


    public Page<Note> findAreaPageNote(String type, Integer currentPage1, Integer rows1, int start) throws SQLException, ClassNotFoundException {
        Page<Note> pageNote = new Page<>();
        //pageNote=PageUtils.findAreaPageNote(type,currentPage1,rows1);
        Integer total = 0;
        total = pageDao.areaTotalNotes(type);
        ArrayList<Note> list = new ArrayList<>();
        list = pageDao.areaNoteList(type, start, rows1);
        pageNote = PageUtils.page(list, currentPage1, rows1, total);
        return pageNote;
    }


    public Page<Note> findUserPageNote(String usename, Integer currentPage1, Integer rows1, int start) throws SQLException, ClassNotFoundException {
        Page<Note> pageNote = new Page<>();
        //pageNote=PageUtils.findUserPageNote(usename,currentPage1,rows1);
        Integer total = 0;
        total = pageDao.userTotalNotes(usename);
        ArrayList<Note> list = new ArrayList<>();
        list = pageDao.userNoteList(usename, start, rows1);
        pageNote = PageUtils.page(list, currentPage1, rows1, total);
        return pageNote;
    }


    public Page<Note> findUserCheckedPageNote(String usename, Integer currentPage1, Integer rows1, int start) throws SQLException, ClassNotFoundException {
        Page<Note> pageNote = new Page<>();
        Integer total = 0;
        total = pageDao.userCheckedNotes(usename);
        ArrayList<Note> list = new ArrayList<>();
        list = pageDao.userCheckedNoteList(usename, start, rows1);
        pageNote = PageUtils.page(list, currentPage1, rows1, total);
        //pageNote=PageUtils.findUserCheckedPageNote(usename,currentPage1,rows1);
        return pageNote;
    }


    public Page<Note> findAreaCheckedPageNote(String type, Integer currentPage1, Integer rows1, int start) throws SQLException, ClassNotFoundException {
        Page<Note> pageNote = new Page<>();
        Integer total = 0;
        total = pageDao.areaTotalCheckedNotes(type);
        ArrayList<Note> list = new ArrayList<>();
        list = pageDao.areaCheckedNoteList(type, start, rows1);
        pageNote = PageUtils.page(list, currentPage1, rows1, total);
        //pageNote=PageUtils.findAreaCheckedPageNote(type,currentPage1,rows1);
        return pageNote;
    }


    public Page<User> findAreaUserPage(String type, Integer currentPage1, Integer rows1, int start) throws SQLException, ClassNotFoundException {
        Page<User> pageUser = new Page<>();
        Integer total = 0;
        total = pageDao.areaTotalNotes(type);
        ArrayList<User> userList = new ArrayList<>();
        userList = pageDao.areaUsersList(type, start, rows1);
        pageUser = PageUtils.page(userList, currentPage1, rows1, total);
        // pageUser=PageUtils.findAreaUserPage(type,currentPage1,rows1);
        return pageUser;
    }


    public Page<Note> afterSearchPage(Integer currentPage1, Integer rows1, String content, int start) throws SQLException, ClassNotFoundException {
        Page<Note> pageNote = new Page<>();
        Integer total = 0;
        total = pageDao.afterSearchTotalNotes(content);
        ArrayList<Note> list = new ArrayList<>();
        list = pageDao.afterSearchNotesList(start, rows1, content);
        pageNote = PageUtils.page(list, currentPage1, rows1, total);
        //pageNote=PageUtils.afterSearchPage(currentPage1,rows1,content);
        return pageNote;
    }


    public Page<Note> afterExatSearchPage(Integer currentPage1, Integer rows1, String labelSearch, int start) throws SQLException, ClassNotFoundException {
        Page<Note> pageNote = new Page<>();
        Integer total = 0;
        total = pageDao.afterExatSearchTotalNotes(labelSearch);
        ArrayList<Note> list = new ArrayList<>();
        list = pageDao.afterExatSearchNotesList(start, rows1, labelSearch);
        pageNote = PageUtils.page(list, currentPage1, rows1, total);
        //pageNote=PageUtils.afterExatSearchPage(currentPage1,rows1,labelSearch);
        return pageNote;
    }
}
